package com.unicorn.base;

import com.unicorn.util.JsonResponse;
import com.unicorn.util.UnicornHttpRequestHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by windy on 16-11-3.
 */
@Component
public class BaseController {

    @Autowired
    protected UnicornHttpRequestHandler  requestHandler;

    @Autowired
    protected HttpServletRequest request;

    @Autowired
    protected HttpServletResponse response;

    @Autowired
    protected JsonResponse jsonResponse;

    protected String basePath;


    public JsonResponse getJsonResponse() {
        return jsonResponse;
    }

    public void setJsonResponse(JsonResponse jsonResponse) {
        this.jsonResponse = jsonResponse;
    }

    public UnicornHttpRequestHandler getRequestHandler() {
        return requestHandler;
    }

    public String getBasePath() {
        if(basePath==null){
             basePath=request.getServletContext().getRealPath("/");

        }
        return basePath;
    }



    public void setRequestHandler(UnicornHttpRequestHandler requestHandler) {
        this.requestHandler = requestHandler;
    }
}
